package com.study.spmongodb.wwj.thread2.char09;

import java.util.Random;

/**
 * @author study
 * @version 1.0
 * @date 2020/12/8 17:07
 */
public class ClientThread extends Thread {
    private final RequestQueue requestQueue;

    private final Random random;

    private final String sendValue;

    public ClientThread(RequestQueue requestQueue, String sendValue) {
        this.requestQueue = requestQueue;
        this.sendValue = sendValue;
        this.random = new Random(System.currentTimeMillis());
    }

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println("Client -> request " + sendValue);
            requestQueue.putRequest(new Request(sendValue));
            try {
                Thread.sleep(random.nextInt(100));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
